//
//  FR_AccountViewController.m
//  FaceRecognition
//
//  Created by syun on 17/2/15.
//  Copyright © 2017年 Sylar. All rights reserved.
//

#import "FR_AccountViewController.h"
#import "FR_MyAcountViewController.h"
#import "FR_AdministratorAcountViewController.h"
#import "FR_TeacherAcountViewController.h"

#import "SY_TeacherFormViewController.h"//老师统计
#import "SY_AllTeacherSFormViewController.h"//全校老师
#import "SY_ManagerFormViewController.h"//个人统计
#import "SY_SchoolFormViewController.h"//全校学生
@interface FR_AccountViewController ()<UITableViewDelegate,UITableViewDataSource>
{
   long long schoolManager;//>0是管理员

    long haveClass;
}
@property (nonatomic, strong)UITableView * table;
@end

@implementation FR_AccountViewController
- (UITableView *)table
{
    if (_table == nil) {
        
        _table = [[UITableView alloc]initWithFrame:CGRectMake(0,64, SCREENWIDTH, SCREENHEIGH-64-49) style:UITableViewStylePlain];
        _table.delegate = self;
        _table.dataSource = self;
        _table.separatorStyle = UITableViewCellSeparatorStyleNone;
        _table.backgroundColor = [UIColor colorWithHexString:@"f5f8fa"];
        [_table setShowsVerticalScrollIndicator:NO];
        
    }
    return _table;
}
- (id)init
{
    self = [super init];
    if (self) {
        
        self.hidesBottomBarWhenPushed = YES;
        
    }
    return self;
}

- (void)requestClassList {
    
    NSMutableDictionary * paramDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [paramDic setObject:USERID forKey:@"teacherid"];
    [paramDic setObject:SCHOOLID forKey:@"scid"];
    [paramDic setObject:[SYAccountTool ShareAccount].account.schoolManage > 0?@"1":@"0" forKey:@"type"];
    
    [Utils Java_get:@"api/getTeacherClass" parameters:paramDic success:^(NSInteger recode, id jsonObject) {
        
        NSArray *arr = [jsonObject objectForKey:@"re_data"];
        
        if (arr.count == 0) {  //没有班级
            
            self->haveClass = 0;
            
        }else if(arr.count > 0){ //有班级
            
            self->haveClass = 1;
            
        }
        
        [self.table reloadData];
    } failure:^(NSInteger recode, NSError *error) {
        
    }];
    
    /*
    NSMutableDictionary * paramDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [paramDic setObject:@"sy_rollcall_classlist" forKey:@"method"];
    [paramDic setObject:USERID forKey:@"teacherid"];
    
    [Utils get:nil parameters:paramDic success:^(NSInteger recode, id jsonObject) {
        
        NSArray *arr = [jsonObject objectForKey:@"re_data"];
        
        if (arr.count == 0) {  //没有班级
            
            self->haveClass = 0;
            
        }else if(arr.count > 0){ //有班级
            
            self->haveClass = 1;
            
        }
        
        [self.table reloadData];
        
        
    } failure:^(NSInteger rocode, NSError * error){
        
    }];
     */

}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navBar.navigationItem.title = @"统计";
    self.view.backgroundColor = [UIColor colorWithHexString:@"f5f8fa"];
    schoolManager = [SYAccountTool ShareAccount].account.schoolManage;
    [self requestClassList];
    
    [self.view addSubview:self.table];
    // Do any additional setup after loading the view.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

//    if (haveClass > 0 && schoolManager == 0)
//    {
//        return 1;
//    }else
//    {
//        return 2;
//    }
    return 1;
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    return 10;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView * view =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 10)];
    view.backgroundColor = [UIColor colorWithHexString:@"f5f8fa"];
    return view;
 
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CMainCell = @"CMainCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CMainCell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier: CMainCell];
    }
    
    if (haveClass > 0 && schoolManager == 0)//只是老师
    {
//        if (indexPath.section == 0) {
        
            cell.textLabel.text = @"班级统计";
            
//        }else {
//
//            cell.textLabel.text = @"个人统计";
//        }
    }else
    {
//        if (indexPath.section == 0) {
        
            cell.textLabel.text = @"班级统计";
            
//        }else if (indexPath.section == 1) {
//
//            cell.textLabel.text = @"员工统计";
//
//        }else {
//
//            cell.textLabel.text = @"个人统计";
//        }
        
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//     if (haveClass >0 && schoolManager > 0) {
//
//        if (indexPath.section == 0) {
//
//            FR_TeacherAcountViewController * teaVC = [[FR_TeacherAcountViewController alloc]init];
//            [self.navigationController pushViewController:teaVC animated:YES];
//
//        }else if (indexPath.section == 1)
//        {
//            FR_AdministratorAcountViewController * adminVC =[[FR_AdministratorAcountViewController alloc]init];
//            [self.navigationController pushViewController:adminVC animated:YES];
//
//        }else
//        {
//            FR_MyAcountViewController * myVC =[[FR_MyAcountViewController alloc]init];
//            [self.navigationController pushViewController:myVC animated:YES];
//        }
//     }else if (haveClass == 0 && schoolManager >0)
//     {
//         if (indexPath.section == 0)
//         {
//             FR_AdministratorAcountViewController * adminVC =[[FR_AdministratorAcountViewController alloc]init];
//             [self.navigationController pushViewController:adminVC animated:YES];
//
//         }else
//         {
//             FR_MyAcountViewController * myVC =[[FR_MyAcountViewController alloc]init];
//             [self.navigationController pushViewController:myVC animated:YES];
//         }
//
//     }else if (haveClass > 0 && schoolManager == 0)
//     {
//         if (indexPath.section == 0) {
//
//             FR_TeacherAcountViewController * teaVC = [[FR_TeacherAcountViewController alloc]init];
//             [self.navigationController pushViewController:teaVC animated:YES];
//
//         }else
//         {
//             FR_MyAcountViewController * myVC =[[FR_MyAcountViewController alloc]init];
//             [self.navigationController pushViewController:myVC animated:YES];
//         }
//     }
    
    if (haveClass > 0 && schoolManager == 0)
    {
//        if (indexPath.section == 0) {
        
            SY_TeacherFormViewController * VC = [[SY_TeacherFormViewController alloc]init];
            [self.navigationController pushViewController:VC animated:YES];
//        }else
//        {
//            SY_ManagerFormViewController *VC = [[SY_ManagerFormViewController alloc]init];
//            [self.navigationController pushViewController:VC animated:YES];
//
//        }
        
    }else
    {
//        if (indexPath.section == 0) {
        
            SY_SchoolFormViewController * VC = [[SY_SchoolFormViewController alloc]init];
            [self.navigationController pushViewController:VC animated:YES];
//        }else if (indexPath.section == 1)
//        {
//            SY_AllTeacherSFormViewController * VC =[[SY_AllTeacherSFormViewController alloc]init];
//            [self.navigationController pushViewController:VC animated:YES];
//
//        }
        
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
